<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组排序</title>
</head>

<body>
    <p>数组排序：</p>
    <script>
        document.write('对数组 var arr = [1, 2, 5, 3, 4,8,7,9,6] 进行排序(升序)。', '<br>');
        var arr = [1, 5, 3, 4, 8, 7, 9,2, 6];
        var newArr = function (arr,fn) {
            for (var i = 0; i < arr.length; i++) {
                for (var j = i; j < arr.length; j++) {
                    if (arr[i] > arr[j]) {
                        arr[i] = arr[i] + arr[j];
                        arr[j] = arr[i] - arr[j];
                        arr[i] = arr[i] - arr[j];
                    }
                }
            }
            blarr(arr);
        }
        var blarr = function (arr) {
            for (var value of arr) {
                document.write(value, ',\t');
            }
        }
        newArr(arr,blarr);
    </script>
</body>

</html>